package com.colabo.j2ee.web.core.dao.extension.ibatis;


/**
 * ORACLE数据库方言
 */
public class OracleDialect implements IDialect {
	private static String ORACLE_PAGEDSQL_FORMATTER = "SELECT * FROM (SELECT A.*, ROWNUM RN FROM (%z%) A WHERE ROWNUM <= %x%) WHERE RN >= %y%";

	public String getPagedString(String sql, boolean hasOffset) {
		return null;
	}

	/**
	 * offset在当前框架中是从intelliweb传过来的，从0开始
	 */
	public String getPagedString(String sql, int offset, int limit) {
		offset = offset + 1;
		int endset = offset + limit - 1;
//		String rs = ORACLE_PAGEDSQL_FORMATTER.replaceFirst("%z%", sql).replaceFirst("%y%", offset + "").replaceFirst(
//				"%x%", endset + "");
		
		String rs = ORACLE_PAGEDSQL_FORMATTER.replaceFirst("%y%", offset + "").replaceFirst("%x%", endset + "").replaceFirst("%z%", sql);

		return rs;
	}

	public boolean supportsPaged() {
		return true;
	}
}
